import 'package:flutter/material.dart';

/// UI组件库文字样式令牌
/// 基于Material Design 3文字排版系统
class UITextStyles {
  // Display 系列 - 大标题
  static TextStyle displayLarge = const TextStyle(
    fontSize: 57,
    fontWeight: FontWeight.w400,
    letterSpacing: -0.25,
    height: 1.12,
  );

  static TextStyle displayMedium = const TextStyle(
    fontSize: 45,
    fontWeight: FontWeight.w400,
    letterSpacing: 0,
    height: 1.16,
  );

  static TextStyle displaySmall = const TextStyle(
    fontSize: 36,
    fontWeight: FontWeight.w400,
    letterSpacing: 0,
    height: 1.22,
  );

  // Headline 系列 - 标题
  static TextStyle headlineLarge = const TextStyle(
    fontSize: 32,
    fontWeight: FontWeight.w400,
    letterSpacing: 0,
    height: 1.25,
  );

  static TextStyle headlineMedium = const TextStyle(
    fontSize: 28,
    fontWeight: FontWeight.w400,
    letterSpacing: 0,
    height: 1.29,
  );

  static TextStyle headlineSmall = const TextStyle(
    fontSize: 24,
    fontWeight: FontWeight.w400,
    letterSpacing: 0,
    height: 1.33,
  );

  // Title 系列 - 小标题
  static TextStyle titleLarge = const TextStyle(
    fontSize: 22,
    fontWeight: FontWeight.w400,
    letterSpacing: 0,
    height: 1.27,
  );

  static TextStyle titleMedium = const TextStyle(
    fontSize: 16,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.15,
    height: 1.50,
  );

  static TextStyle titleSmall = const TextStyle(
    fontSize: 14,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.1,
    height: 1.43,
  );

  // Body 系列 - 正文
  static TextStyle bodyLarge = const TextStyle(
    fontSize: 16,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.5,
    height: 1.50,
  );

  static TextStyle bodyMedium = const TextStyle(
    fontSize: 14,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.25,
    height: 1.43,
  );

  static TextStyle bodySmall = const TextStyle(
    fontSize: 12,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.4,
    height: 1.33,
  );

  // Label 系列 - 标签
  static TextStyle labelLarge = const TextStyle(
    fontSize: 14,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.1,
    height: 1.43,
  );

  static TextStyle labelMedium = const TextStyle(
    fontSize: 12,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.5,
    height: 1.33,
  );

  static TextStyle labelSmall = const TextStyle(
    fontSize: 11,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.5,
    height: 1.45,
  );

  // UI组件专用样式
  static TextStyle get button => labelLarge.copyWith(
    fontWeight: FontWeight.w600,
  );

  static TextStyle get buttonSmall => labelMedium.copyWith(
    fontWeight: FontWeight.w600,
  );

  static TextStyle get caption => labelSmall.copyWith(
    fontWeight: FontWeight.w400,
  );

  static TextStyle get overline => labelSmall.copyWith(
    fontWeight: FontWeight.w500,
    letterSpacing: 1.5,
  );

  // 组件特定样式
  static TextStyle get cardTitle => titleMedium.copyWith(
    fontWeight: FontWeight.w600,
  );

  static TextStyle get cardSubtitle => bodyMedium.copyWith(
    fontWeight: FontWeight.w400,
  );

  static TextStyle get dialogTitle => headlineSmall.copyWith(
    fontWeight: FontWeight.w500,
  );

  static TextStyle get dialogContent => bodyMedium;

  static TextStyle get listTitle => bodyLarge.copyWith(
    fontWeight: FontWeight.w500,
  );

  static TextStyle get listSubtitle => bodyMedium;

  static TextStyle get listCaption => caption;

  // 状态文字样式
  static TextStyle get loadingText => bodyMedium.copyWith(
    fontWeight: FontWeight.w500,
  );

  static TextStyle get errorText => bodyMedium.copyWith(
    fontWeight: FontWeight.w500,
  );

  static TextStyle get successText => bodyMedium.copyWith(
    fontWeight: FontWeight.w500,
  );

  static TextStyle get emptyStateTitle => titleMedium.copyWith(
    fontWeight: FontWeight.w500,
  );

  static TextStyle get emptyStateSubtitle => bodyMedium;

  // 响应式文字大小调整
  static TextStyle responsive(TextStyle base, double scaleFactor) {
    return base.copyWith(
      fontSize: (base.fontSize ?? 14) * scaleFactor,
    );
  }

  // 获取适合不同屏幕的文字样式
  static TextStyle getResponsiveStyle(TextStyle base, BuildContext context) {
    final screenWidth = MediaQuery.of(context).size.width;
    double scaleFactor = 1.0;
    
    if (screenWidth < 600) {
      scaleFactor = 0.9; // 手机
    } else if (screenWidth < 1200) {
      scaleFactor = 1.0; // 平板
    } else {
      scaleFactor = 1.1; // 桌面
    }
    
    return responsive(base, scaleFactor);
  }
}